<?php

	function kses_init()
	{
		global $CONFIG;
		
		register_plugin_hook('validate', 'input', 'kses_filter_tags', 1);
	}
	
	/**
	 * Kses filtering of tags, called on a plugin hook
	 *
	 * @param mixed $var Variable to filter
	 * @return mixed
	 */
	function kses_filter_tags($hook, $entity_type, $returnvalue, $params)
	{
		$return = $returnvalue;
		$var = $returnvalue;
		
		if (include_once(dirname(__FILE__) . "/kses.php")) {
			
			global $CONFIG;
			
			
			if (!is_array($var)) {
				$return = "";
				$return = wp_kses($var);
			} else {
				$return = array();
				
				foreach($var as $key => $el) {
					$return[$key] = wp_kses($el);
				}
			}
		}
	
		return $return;
	}
	
	
	register_elgg_event_handler('init','system','kses_init');    
?>